import java.net.*;
import java.util.*;
import java.io.*;

public class MyHost
       {
 public static void main(String [] args)
 {
          if(args.length==0||args.length!=1)
         {  System.out.println("USAGE: java MyHost [port]");
            System.exit(0);  }
 else  { new MyHost(Integer.parseInt(args[0]));  }
 }

       MyHost(int port)
       {
	System.out.println("Server started...");
try{
	ServerSocket ss = new ServerSocket(port);
	Socket s;
	ObjectInputStream  ios;
	ObjectOutputStream oos;
    while(true)
    {   s = ss.accept();
        ios = new ObjectInputStream(s.getInputStream());
        oos = new ObjectOutputStream(s.getOutputStream());
double matrix1[][] = (double[][])ios.readObject();
double matrix2[][] = (double[][])ios.readObject();
oos.writeObject(getMatrix(matrix1,matrix2)); oos.flush();  

double matrix3[][] = (double[][])ios.readObject();
double matrix4[][] = (double[][])ios.readObject();
oos.writeObject(getMatrix(matrix3,matrix4)); oos.flush();  

    }  
}catch(Exception ioe) {ioe.printStackTrace();}
          }

public double [][] getMatrix(double [][] matrix1, double [][] matrix2)
{ 
 double [][] matrix = new double[matrix1.length][matrix2[0].length];
  int c=0;
  while(c!=matrix[0].length)
  { 
   for(int i=0;i<matrix1.length;i++) 
   {double tmp_sum=0; 		  
    for(int s=0;s<matrix1[0].length;s++)       
     tmp_sum+=matrix1[i][s]*matrix2[s][c];
     matrix[i][c]=tmp_sum;
   } c++;  
  }
  return matrix;  
}
  
}

